package com.tang.common.utils.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.springframework.stereotype.Controller;

import java.io.InputStream;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

public class ExcelUtils {


    /**
     * 设置表格内容居中显示策略
     *
     * @return
     */
    public static HorizontalCellStyleStrategy getStyleStrategy() {
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();

        headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.index);
        //设置头字体
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontHeightInPoints((short) 10);
        headWriteFont.setBold(true);
        headWriteCellStyle.setWriteFont(headWriteFont);
        headWriteFont.setFontName("宋体");
        //设置头居中
        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);

        // 内容策略
        WriteCellStyle writeCellStyle = new WriteCellStyle();
        // 设置内容水平居中
        writeCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);

        //垂直居中,水平居中
        writeCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        writeCellStyle.setBorderLeft(BorderStyle.THIN);
        writeCellStyle.setBorderTop(BorderStyle.THIN);
        writeCellStyle.setBorderRight(BorderStyle.THIN);
        writeCellStyle.setBorderBottom(BorderStyle.THIN);
        writeCellStyle.setWriteFont(headWriteFont);

        //设置 自动换行
        //contentWriteCellStyle.setWrapped(true);

        return new HorizontalCellStyleStrategy(headWriteCellStyle, writeCellStyle);
    }




    public static void main(String[] args) {
//        List<Demo> demoList = new ArrayList<>();
//        EasyExcel.read("/Users/cool/Desktop/物料上传模版.xlsx", Demo.class, new AnalysisEventListener<Demo>() {
//                    @Override
//                    public void invoke(Demo demo, AnalysisContext analysisContext) {
//                        System.out.println(demo);
//                        demoList.add(demo);
//                    }
//
//                    @Override
//                    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
//                    }
//                })
//                .sheet().doRead();


    }
}
